<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" labelWidth="73"  :show-search-button="true"
                    @search="search" :left="false">
        <el-form-item label="分销商:" prop="useruuid" v-if="isCompetence">
          <el-select v-model="filters.useruuid" placeholder="请选择分销商" clearable  filterable >
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in users"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="充值号码:">
          <el-input v-model="filters.phoneNum" placeholder="充值号码" clearable></el-input>
        </el-form-item>
        <el-form-item label="开始时间:">
          <el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd"  clearable v-model="filters.starttime"
                          style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间:">
          <el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd" clearable v-model="filters.endtime"
                          style="width: 100%;"></el-date-picker>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
        </template>
      </data-table>
    </template>

    <template #dialog>
    </template>

  </base-layout>
</template>

<script>
  import baseMixin from '@/mixins/base'
  import { findPageDebitLog } from '@/api/downapi'
  import { findAllPro,findAllDownShopInfo } from '@/api/utilsapi'
  import util from "../../../utils/util";
  import moment from 'moment';

  export default {
    name: 'debitlog',
    mixins: [
      baseMixin({
        idName: 'id',
        refresh: '',
        findData: findPageDebitLog,
        format(res) {
          return res.map(data => {
            return data
          })
        }
      })
    ],
    data() {
      return {
        buttons: [],
        pageShow: true,
        isCompetence: util.checkRoleAdminAndSuper() ? true : false,
        dialogData:{},
        users:[],
        tableColumnAttributes: [
          //充值号码	扣款金额	扣款后余额	扣款时间	扣款状态
          { name: '充值号码', value: 'dowonphonenum' , formatter:this.dowonphonenumFormatter},
          { name: '扣款金额', value: 'debitAmount' },
          { name: '扣款后余额', value: 'balance' },
          { name: '扣款时间', value: 'debitTime' },
          { name: '扣款状态', value: 'debitStatus'}
        ],
        filters: {
          starttime:  moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') ,
          endtime: '',
          useruuid: '',
          phoneNum:''
        }
      }
    },
    methods: {
      async search(form){
        let para = {
          start: 0,
          pageSize: 10,
          starttime: this.filters.starttime = (!this.filters.starttime || this.filters.starttime == '') ? '' : util.formatDate.format(new Date(this.filters.starttime), 'yyyy-MM-dd'),
          endtime: this.filters.endtime = (!this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date(this.filters.endtime), 'yyyy-MM-dd'),
          useruuid: this.filters.useruuid == "0" ? "": this.filters.useruuid,
          phoneNum:this.filters.phoneNum
        };
        this.searchOptions = para;
        this.setTableData()
      },
      dowonphonenumFormatter(row){
        return row.downOrder.dowonphonenum;
      },
      findAllDownShopInfo: function () {
        let para = {useruuid:sessionStorage.getItem("useruuid_hf")};
        findAllDownShopInfo(para).then(datas => {
          if(datas.data){
            this.users = datas.data;
          }
        });
      }
    },
    mounted() {
      this.findAllDownShopInfo();
    }
  }
</script>
